const
	path = require('path'),
	blogEngine = require('../blog')
;
module.exports = function (app) {
	app.get('/', function (req, res) {
		res.render('index', { title: '最新文章', entries: blogEngine.getBlogEntries() });
	});

	app.get('/about', function (req, res) {
		res.render('about', { title: '自我介绍' })
	});

	app.get('/article/:id', function (req, res, next) {
		if(req.params.id > blogEngine.getBlogEntries().length) {
			return next();
		}
		const
			entry = blogEngine.getBlogEntry(req.params.id)
		;
		res.render('article', { title: entry.title, blog: entry });
	});

	app.get('*', function(req, res) {
		res.sendfile(path.resolve(process.cwd(), '../public/views/error.html'));
	});
};